﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using Steve.EFDataLayer;
using Steve.UI.Extensions;
using Steve.UI.Extensions.Html;
using Steve.UI;
using Steve.Lucene;
using Steve.Jobs;

namespace Steve.ConsoleWorker
{
    class Program
    {
        static void Main(string[] args)
        {
            var catalog = new TypeCatalog(
                typeof(DefaultConfiguration),
                typeof(ConsoleLoggingService),
                typeof(MemoryCacheService),
                typeof(NullAccountService),
                typeof(NullHttpContextBaseBuilder),
                typeof(DefaultRewriter),
                typeof(LuceneSearchService),

                typeof(CacheServiceDirectoryBuilder),

                typeof(HtmlContentDataHandler),
                typeof(TextContentDataHandler),
                typeof(NullContentDataHandler),

                typeof(EFContentRepository),
                typeof(EFSiteExplorerRepository),
                typeof(EFContentTypeRepository),
                typeof(EFCategoryRepository));

            var container = new CompositionContainer(catalog);

            var categorizer = new AutomatedCategorizer();

            var index = container.GetExportedValue<ISearchIndexService>();

            index.RebuildIndex();

            container.ComposeParts(categorizer);

            categorizer.Run();

            //var search = container.GetExportedValue<ISearchQueryService>();

            //Console.WriteLine("\n\n");

            //Console.Write("{0}, {1} or {2}:", SearchType.Latest, SearchType.LatestApproved, SearchType.RevisionHistory);
            //var type = (SearchType) Enum.Parse(typeof(SearchType), Console.ReadLine(), true);

            //Console.Write("Enter search text:");
            //var line = Console.ReadLine();

            //while (!string.IsNullOrWhiteSpace(line))
            //{
            //    var results = search.Search(type, line);

            //    Console.WriteLine("{0} total, {1} shown, {2} max score", results.TotalCount, results.ItemCount, results.MaxScore);

            //    foreach (var r in results.Items)
            //    {
            //        Console.WriteLine("{0}: {1}", r.NormalizedScore, r.Title);
            //    }

            //    Console.WriteLine("\n\n");

            //    Console.Write("{0}, {1} or {2}:", SearchType.Latest, SearchType.LatestApproved, SearchType.RevisionHistory);
            //    type = (SearchType)Enum.Parse(typeof(SearchType), Console.ReadLine(), true);

            //    Console.Write("Enter search text:");
            //    line = Console.ReadLine();
            //}
        }
    }
}
